import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { parse } from 'yaml';
import * as fs from 'fs';
import * as path from 'path';

const config = () => {
  try {
    return parse(
      fs.readFileSync(path.join(__dirname, '../config/config.yaml'), 'utf8'),
    ) as Record<string, any>;
  } catch (error) {
    console.error('Error loading YAML config:', error);
    return {};
  }
};

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [config],
      isGlobal: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
